package com.shujia

/**
 * trait ：Scala中的特征，类似Java中的抽象类，又向Java中的接口
 *
 */

trait MyTrait01 {
  val _id01: String = "001"
  val _name01: String = "zs"
  val _age01: Int = 20

  // 定义方法：具体的或者抽象的
  def isEqual01(age: Int): Boolean

  def isNotEqual01(age: Int): Boolean = {
    !isEqual01(age)
  }

}

trait MyTrait02 {
  val _id02: String = "002"
  val _name02: String = "ls"
  val _age02: Int = 22

  // 定义方法：具体的或者抽象的
  def isEqual02(age: Int): Boolean

  def isNotEqual02(age: Int): Boolean = {
    !isEqual02(age)
  }

}

class P{
  val gender:String = "男"
}

class Q extends P with MyTrait01 with MyTrait02 {
  override def isEqual01(age: Int): Boolean = {
    _age01 == age
  }

  override def isEqual02(age:Int):Boolean = {
    _age02 == age
  }
}


object Demo23Trait {
  def main(args: Array[String]): Unit = {
    // 创建对象
    val q: Q = new Q

    println(q.gender) // 从父类继承过来的
    println(q._name01) // 从MyTrait01中继承过来的
    println(q._name02) // 从MyTrait02中继承过来的

    println(q.isEqual01(20))
    println(q.isNotEqual01(20))
    println(q.isEqual02(22))
    println(q.isNotEqual02(22))
  }

}
